home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / CLEARS.ASM < prev    next >
Assembly Source File  |  1988-09-01  |  5KB  |  126 lines

  1. ;===========================================================================
  2. ;
  3. ;    C L E A R S  -  Screen clear primitive for Turbo Pascal
  4. ;
  5. ;===========================================================================
  6. ;
  7. ;     by Jeff Duntemann      12 February 1988
  8. ;
  9. ;     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann
  10. ;    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5
  11. ;
  12. ; CLEARS is written to be called from Turbo Pascal V4.0 using the
  13. ; {$L}/EXTERNAL procedure convention.  It has the advantage over ClrScr in
  14. ; that it can clear a screen stored on the heap, and also that a screen can
  15. ; be cleared with a character other than space, like the IBM PC's halftone
  16. ; characters, for the Framework effect.  An attribute can be written to the
  17. ; cleared buffer as well as a clear character.
  18. ;
  19. ; To use CLEARS on the visible screen, you must "doctor" a declared
  20. ; pointer to point to either the monochrome or graphics text buffer:
  21. ;
  22. ; VAR
  23. ;   VisibleScreen : Pointer;
  24. ;
  25. ; VisibleScreen := Ptr($B000,0);  { For the monochrome adapter }
  26. ; VisibleScreen := Ptr($B800,0);  { For the color graphics adapter }
  27. ;
  28. ; Declare the procedure itself as external using this declaration:
  29. ;
  30. ; {$L CLEARS}
  31. ; PROCEDURE CLEARS(Target    : Pointer; ScreenSize : Integer;
  32. ;                  Attribute : Integer; CharFill   : Byte);
  33. ;                  EXTERNAL;
  34. ;
  35. ;
  36. ; Pass CLEARS the attribute code you wish to use in Attribute
  37. ; (typically $0700 for "normal" text display) and the character to "clear"
  38. ; with in CharFill.  Use 32 or Ord(' ') to fill with blanks, or you may use
  39. ; the "halftone" characters (176-178) for Framework style screens.  Keep
  40. ; in mind that the attribute code must be in the HIGH byte of the actual
  41. ; parameter passed to Attribute.
  42. ;
  43. ; EXAMPLES:
  44. ;
  45. ; To clear the visible screen to normal blanks:
  46. ;    CLEARS(VisibleScreen,4096,$0700,' ');
  47. ;
  48. ; To clear a screen on the heap to a halftone screen:
  49. ;    CLEARS(NewScreen,4096,$0700,176);
  50. ;
  51. ; Obviously, you must have declared VisibleScreen and NewScreen and set
  52. ; them up so that they both point to either a screen on the heap or the
  53. ; visible screen buffer.  If the pointer Target has a value of NIL,
  54. ; CLEARS will return to the calling logic without taking any action.
  55. ; Good thing, too--if it did, it would blank your interrupt vector table!
  56. ;
  57. ;
  58. ; To reassemble/relink CLEARS:
  59. ;-------------------------------------
  60. ; Assemble this file with MASM.  "A> MASM CLEARS;"
  61.  
  62. CODE    SEGMENT BYTE PUBLIC
  63.         ASSUME  CS:CODE
  64.         PUBLIC  CLEARS
  65. ;
  66. ; This structure maps the stack at entry to CLEARS:
  67. ;
  68. ONSTACK STRUC
  69. OLDBP   DW ?    ;CALLER'S BP VALUE SAVED ON STACK
  70. RETADDR DW ?    ;NEAR RETURN ADDRESS
  71. FILLER  DW ?    ;CHARACTER THAT FILLS THE CLEARED BUFFER
  72. ATTRIB  DW ?    ;ATTRIBUTE FOR THE CLEARED BUFFER
  73. BUFSIZE DW ?    ;SIZE OF THE BUFFER TO BE CLEARED, IN BYTES
  74. BUFOFS  DW ?    ;OFFSET OF BUFFER ORIGIN
  75. BUFSEG  DW ?    ;SEGMENT OF BUFFER ORIGIN
  76. ENDMRK  DB ?    ;DUMMY LABEL TO MARK END OF DATA ON STACK
  77. ONSTACK ENDS
  78. ;
  79.  
  80.  
  81. CLEARS  PROC    NEAR
  82.         PUSH    BP
  83.         MOV     BP,SP                   ; CALLING CONVENTION
  84. ;
  85. ;----------------------------------------------------
  86. ; FIRST WE TEST FOR BUFFER = NIL...QUIT IF SO
  87. ;----------------------------------------------------
  88. ;
  89.         CMP     WORD PTR [BP].BUFSEG,0  ; A NIL POINTER IS A SEGMENT AND
  90.         JNE     START                   ; OFFSET BOTH SET TO 0
  91.         CMP     WORD PTR [BP].BUFOFS,0
  92.         JE      BYE
  93.  
  94. ;
  95. ;----------------------------------------------------
  96. ; PREPARE THE REGISTERS FOR THE STORE WORD OPERATION
  97. ;----------------------------------------------------
  98. ;
  99. START:  CLD                             ; CLEAR DIRECTION FLAG
  100.         MOV     AX,[BP].ATTRIB          ; LOAD ATTRIBUTE CODE INTO AX
  101.         AND     AX,0FF00H               ; MASK OUT LOW BYTE OF ATTRIBUTE CODE
  102.         MOV     BX,[BP].FILLER          ; LOAD FILLER CODE INTO BX
  103.         AND     BX,0FFH                 ; MASK OUT HIGH BYTE OF FILLER CODE
  104.         OR      AX,BX                   ; AND COMBINE ATTRIB & FILLER INTO AX
  105.         MOV     DI,[BP].BUFOFS          ; SET DI TO TARGET BUFFER OFFSET
  106.         MOV     ES,[BP].BUFSEG          ; SET ES TO TARGET BUFFER SEGMENT
  107. ;
  108. ;---------------------------------------------------------------
  109. ; LOOP TO STORE CHARACTER AND ATTRIBUTE INTO BUFFER BY WORD MOVE
  110. ;---------------------------------------------------------------
  111. ;
  112.         MOV     CX,[BP].BUFSIZE         ; SET UP COUNTER WITH BUFFER SIZE
  113.         REP     STOSW                   ; DO THE STRING STORE
  114. ;
  115. ;------------------------------------
  116. ; DONE.. CLEAN UP THE STACK AND LEAVE
  117. ;------------------------------------
  118. ;
  119. BYE:    MOV     SP,BP                   ; RESTORE PRIOR STACK POINTER & BP
  120.         POP     BP                      ;  IN CONVENTIONAL RETURN
  121.         RET     ENDMRK-RETADDR-2        ; TRASH 10 BYTES FOR PARMS
  122.  
  123. CLEARS  ENDP
  124. CODE    ENDS
  125.         END
  126.